package com.smartum.mpr.server.utils;

import java.io.IOException;
import java.util.Properties;

/**
 * Helps read connection properties from <code>connection.properties</code> file.
 */
public final class ConnectionPropertyReader {
    private static final String CONNECTION_PROPERTY_FILE = "connection.properties";
    private static final String CONNECTION_PROPERTY = "connection.url";
    private static final String USER_AUTHORIZATION_SERVICE = "/user/authorization";
    private static final String UNCINFIRMED_IMAGES_SERVICE = "/photo/get/unconfirmed";
    private static final String MODERATE_IMAGES_SERVICE = "/photo/moderation";
    private static final String MODERATE_NEWS_SERVICE = "/news/get/all";
    private static final String ADD_NEWS_SERVICE = "/news/post";
    private static final String DELETE_NEWS_SERVICE = "/news/delete";
    private static final String UPDATE_NEWS_SERVICE = "/news/update/model";
    private static final String GET_NEWS_BY_ID_SERVICE = "/news/get/one";
    private static final String UPDATE_NEWS_PHOTO_SERVICE = "/news/update/photo";
    private static final String ITEMS_SERVICE = "/static/item/categories";
    private static final String SUBITEMS_SERVICE = "/static/item/subcategories";
    private static final String ADDITEMS_SERVICE = "/static/item/category/add";
    private static final String ADDSUBITEMS_SERVICE = "/static/item/subcategory/add";
    private static final String JOBS_SERVICE = "/static/job/categories";
    private static final String SUBJOBS_SERVICE = "/static/job/subcategories";
    private static final String ADDJOBS_SERVICE = "/static/job/category/add";
    private static final String ADDSUBJOBS_SERVICE = "/static/job/subcategory/add";
    private static final String DELETESUBCATEGORY_SERVICE = "/static/item/subcategory/delete";
    private static final String EDITCATEGORIES_SERVICE = "/static/item/category/update";
    private static final String DELETECATEGORIES_SERVICE = "/static/item/category/delete";
    private static final String EDITSUBCATEGORY_SERVICE = "/static/item/subcategory/update";
    private static final String DELETEJOBSUBCATEGORY_SERVICE = "/static/job/subcategory/delete";
    private static final String EDITJOBCATEGORIES_SERVICE = "/static/job/category/update";
    private static final String DELETEJOBCATEGORIES_SERVICE = "/static/job/category/delete";
    private static final String EDITJOBSUBCATEGORY_SERVICE = "/static/job/subcategory/update";

    /**
     * Reads <code>connection.properties</code> file on classpath.
     *
     * @return {@link Properties properties} with all necessary properties for connection
     * @throws IOException
     */
    public static Properties getConnectionProperties() throws IOException {
        final Properties properties = new Properties();
        properties.load(ConnectionPropertyReader.class.getClassLoader().getResourceAsStream(CONNECTION_PROPERTY_FILE));

        return properties;
    }

    public static String getUserAuthorizationServiceURL() throws IOException {
        return getConnectionProperties().get(CONNECTION_PROPERTY) + USER_AUTHORIZATION_SERVICE;
    }

    public static String getUnconfirmedImagesURL() throws IOException {
        return getConnectionProperties().get(CONNECTION_PROPERTY) + UNCINFIRMED_IMAGES_SERVICE;
    }

    public static String getModerateImagesURL() throws IOException {
        return getConnectionProperties().get(CONNECTION_PROPERTY) + MODERATE_IMAGES_SERVICE;
    }

    public static String getNewsURL() throws IOException {
        return getConnectionProperties().get(CONNECTION_PROPERTY) + MODERATE_NEWS_SERVICE;
    }

    public static String getAddNewsURL() throws IOException {
        return getConnectionProperties().get(CONNECTION_PROPERTY) + ADD_NEWS_SERVICE;
    }

    public static String getDeleteNewsURL() throws IOException {
        return getConnectionProperties().get(CONNECTION_PROPERTY) + DELETE_NEWS_SERVICE;
    }

    public static String getUpdateNewsURL() throws IOException {
        return getConnectionProperties().get(CONNECTION_PROPERTY) + UPDATE_NEWS_SERVICE;
    }

    public static String getNewsByIdURL() throws IOException {
        return getConnectionProperties().get(CONNECTION_PROPERTY) + GET_NEWS_BY_ID_SERVICE;
    }

    public static String getUpdateNewsPhotoURL() throws IOException {
        return getConnectionProperties().get(CONNECTION_PROPERTY) + UPDATE_NEWS_PHOTO_SERVICE;
    }

    public static String getJobssListURL() throws IOException {
        return getConnectionProperties().get(CONNECTION_PROPERTY) + JOBS_SERVICE;
    }

    public static String getSubjobssListURL() throws IOException {
        return getConnectionProperties().get(CONNECTION_PROPERTY) + SUBJOBS_SERVICE;
    }

    public static String getAddJobsListURL() throws IOException {
        return getConnectionProperties().get(CONNECTION_PROPERTY) + ADDJOBS_SERVICE;
    }

    public static String getAddSubjobsListURL() throws IOException {
        return getConnectionProperties().get(CONNECTION_PROPERTY) + ADDSUBJOBS_SERVICE;
    }

    public static String getItemsListURL() throws IOException {
        return getConnectionProperties().get(CONNECTION_PROPERTY) + ITEMS_SERVICE;
    }

    public static String getSubitemsListURL() throws IOException {
        return getConnectionProperties().get(CONNECTION_PROPERTY) + SUBITEMS_SERVICE;
    }

    public static String getAddItemsListURL() throws IOException {
        return getConnectionProperties().get(CONNECTION_PROPERTY) + ADDITEMS_SERVICE;
    }

    public static String getAddSubitemsListURL() throws IOException {
        return getConnectionProperties().get(CONNECTION_PROPERTY) + ADDSUBITEMS_SERVICE;
    }

    public static String getDeleteSubitemsListURL() throws IOException {
        return getConnectionProperties().get(CONNECTION_PROPERTY) + DELETESUBCATEGORY_SERVICE;
    }

    public static String getDeleteItemsListURL() throws IOException {
        return getConnectionProperties().get(CONNECTION_PROPERTY) + DELETECATEGORIES_SERVICE;
    }

    public static String getEditItemsListURL() throws IOException {
        return getConnectionProperties().get(CONNECTION_PROPERTY) + EDITCATEGORIES_SERVICE;
    }

    public static String getEditSubitemsListURL() throws IOException {
        return getConnectionProperties().get(CONNECTION_PROPERTY) + EDITSUBCATEGORY_SERVICE;
    }

    public static String getDeleteJobSubcategoryListURL() throws IOException {
        return getConnectionProperties().get(CONNECTION_PROPERTY) + DELETEJOBSUBCATEGORY_SERVICE;
    }

    public static String getEditJobCategoryListURL() throws IOException {
        return getConnectionProperties().get(CONNECTION_PROPERTY) + EDITJOBCATEGORIES_SERVICE;
    }

    public static String getDeleteJobCategoryListURL() throws IOException {
        return getConnectionProperties().get(CONNECTION_PROPERTY) + DELETEJOBCATEGORIES_SERVICE;
    }

    public static String getEditSubjobCategoryListURL() throws IOException {
        return getConnectionProperties().get(CONNECTION_PROPERTY) + EDITJOBSUBCATEGORY_SERVICE;
    }
}
